﻿#ifndef __EMSCRIPTEN_API_H__
#define __EMSCRIPTEN_API_H__
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/bind.h>

#include "SmartCar.h"

using namespace emscripten;

#include <functional>
#include <string>

// EMSCRIPTEN_DECLARE_VAL_TYPE(std::function<void(std::string)>);

EMSCRIPTEN_BINDINGS(DarkNet)
{
    register_vector<std::string>("vector<string>");
    register_vector<char>("vector<char>");
    register_vector<unsigned char>("vector<unsigned char>");
    register_map<std::string, std::string>("map<string, string>");

    class_<JsColorModel>("JsColorModel")
        .function("Predict", &JsColorModel::Predict)
        .function("GetClassifyList", &JsColorModel::GetClassifyList);

    class_<JsModelProxy>("JsModelProxy")
        .function("GetClassifyList", &JsModelProxy::GetClassifyList)
        .function("AddTrainData", &JsModelProxy::AddTrainData)
        .function("SetTrainData", &JsModelProxy::SetTrainData)
        .function("DeleteTrainData", &JsModelProxy::DeleteTrainData)
        .function("LoadTrainData", &JsModelProxy::LoadTrainData)
        .function("SaveTrainData", &JsModelProxy::SaveTrainData)
        .function("LoadModel", &JsModelProxy::LoadModel)
        .function("SaveModel", &JsModelProxy::SaveModel)
        .function("DeleteModel", &JsModelProxy::DeleteModel)
        .function("Predict", &JsModelProxy::Predict)
        .function("DoEpoch", &JsModelProxy::DoEpoch)
        .function("SetTrainParams", &JsModelProxy::SetTrainParams)
        .function("JsDownloadDataSet", &JsModelProxy::JsDownloadDataSet)
        .function("GetImageDirectory", &JsModelProxy::GetImageDirectory);

    class_<SmartCar>("SmartCar")
        .smart_ptr_constructor("SmartCar", &std::make_shared<SmartCar>)
        .function("SetRootDirectory", &SmartCar::SetRootDirectory)
        .function("GetJsModelProxy", &SmartCar::GetJsModelProxy)
        .function("TrainBase64ImageColors", &SmartCar::TrainBase64ImageColors)
        .function("DownLoadColorDataSet", &SmartCar::DownLoadColorDataSet)
        .function("GetBase64ImageData", &SmartCar::GetBase64ImageData)
        .function("GetBase64ImageRGB565Data", &SmartCar::GetBase64ImageRGB565Data)
        .function("GetRoadLineClassifyBase64Image", &SmartCar::GetRoadLineClassifyBase64Image)
        .function("PredictRoadLineBase64ImageColor", &SmartCar::PredictRoadLineBase64ImageColor)
        .function("PredictBase64ImageColor", &SmartCar::PredictBase64ImageColor)
        .function("PredictBase64ImageRoadLine", &SmartCar::PredictBase64ImageRoadLine)
        .function("PredictBase64ImageRoadLineNearDirection", &SmartCar::PredictBase64ImageRoadLineNearDirection)
        .function("PredictBase64ImageRoadLineFarDirection", &SmartCar::PredictBase64ImageRoadLineFarDirection)
        .function("PredictBase64ImageRoadSign", &SmartCar::PredictBase64ImageRoadSign)
        .function("GetRoadSignImageRGBDatas", &SmartCar::GetRoadSignImageRGBDatas)
        .function("PredictBase64ImageRoadSignRect", &SmartCar::PredictBase64ImageRoadSignRect);

    function("GetJsColorModelInstance", &JsColorModel::GetInstance, allow_raw_pointers());
}
#endif

#endif
